﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="hanldleAdd()" v-if="hasPerm('transactionbatchsub.Add')">新建</a-button>
      <a-button
      v-if="hasPerm('transactionbatchsub.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除</a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="TBID">代发批次ID</a-select-option>
                <a-select-option key="PaymentOutBatchNo">代发编号</a-select-option>
                <a-select-option key="PaymentOutOrderNo">订单号</a-select-option>
                <a-select-option key="BeneficiaryName">收款人姓名</a-select-option>
                <a-select-option key="BeneficiaryAccountNumber">收款人账号</a-select-option>
                <a-select-option key="idCardNo">身份证号码</a-select-option>
                <a-select-option key="Description">说明</a-select-option>
                <a-select-option key="systemCheck">审核</a-select-option>
                <a-select-option key="employeeId">人员ID</a-select-option>
                <a-select-option key="BankName">银行名称</a-select-option>
                <a-select-option key="charge">charge</a-select-option>
                <a-select-option key="trxSts">交易状态</a-select-option>
                <a-select-option key="trxId">上游单号</a-select-option>
                <a-select-option key="trxCrtTm">trxCrtTm</a-select-option>
                <a-select-option key="trxFnshDtTm">完成日期</a-select-option>
                <a-select-option key="ordrId">订单号</a-select-option>
                <a-select-option key="sysRtnDesc">返回信息</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {this.pagination.current = 1; this.getDataList()}">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :columns="columns"
      :rowKey="row => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.Id)" v-if="hasPerm('transactionbatchsub.Edit')">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗？"
          v-if="hasPerm('transactionbatchsub.Delete')"
    ok-text="确定"
    cancel-text="取消"
    @confirm="handleDelete([record.Id])"
    @cancel="cancel"
  >
    <a href="#">删除</a>
  </a-popconfirm>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'

const columns = [
  { title: '代发批次ID', dataIndex: 'TBID', width: '10%' },
  { title: '代发编号', dataIndex: 'PaymentOutBatchNo', width: '10%' },
  { title: '订单号', dataIndex: 'PaymentOutOrderNo', width: '10%' },
  { title: '金额', dataIndex: 'PaymentOutAmount', width: '10%' },
  { title: '收款人姓名', dataIndex: 'BeneficiaryName', width: '10%' },
  { title: '收款人账号', dataIndex: 'BeneficiaryAccountNumber', width: '10%' },
  { title: '身份证号码', dataIndex: 'idCardNo', width: '10%' },
  { title: '说明', dataIndex: 'Description', width: '10%' },
  { title: '审核', dataIndex: 'systemCheck', width: '10%' },
  { title: '人员ID', dataIndex: 'employeeId', width: '10%' },
  { title: '银行名称', dataIndex: 'BankName', width: '10%' },
  { title: 'charge', dataIndex: 'charge', width: '10%' },
  { title: '交易状态', dataIndex: 'trxSts', width: '10%' },
  { title: '上游单号', dataIndex: 'trxId', width: '10%' },
  { title: 'trxCrtTm', dataIndex: 'trxCrtTm', width: '10%' },
  { title: '完成日期', dataIndex: 'trxFnshDtTm', width: '10%' },
  { title: '订单号', dataIndex: 'ordrId', width: '10%' },
  { title: '返回信息', dataIndex: 'sysRtnDesc', width: '10%' },
  { title: '取消日期', dataIndex: 'CancelDate', width: '10%' },
  { title: '单笔服务费', dataIndex: 'fee', width: '10%' },
  { title: '是否发送短信', dataIndex: 'sendsmsstatus', width: '10%' },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    EditForm
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_transactionbatchsub/leasesystem_transactionbatchsub/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this
     
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_leasesystem_transactionbatchsub/leasesystem_transactionbatchsub/DeleteData', ids).then(resJson => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
    },
    cancel(e) {
      this.$message.error('已取消删除');
    }
  }
}
</script>

<style>
.ant-table-thead > tr > th
{
  font-weight: 600;
  color: #333333;
}
</style>